﻿using System.Collections.Generic;

namespace Complaint.Models.Dtos.JavascriptConverters
{
    public static class Utility
    {
        public static T GetDictionaryValueJson<T>(IDictionary<string, object> dictionary, string key)
        {
            if (dictionary.ContainsKey(key))
            {
                if (typeof(T) == typeof(string))
                {
                    object o = string.Empty;
                    return string.IsNullOrEmpty(dictionary[key] as string) ? (T)o : (T)dictionary[key];
                }
                return dictionary[key] is T ? (T)dictionary[key] : default(T);
            }

            return default(T);
        }
    }
}